package com.hxtec.polaris.service.impl;

import com.hxtec.polaris.entity.ShopStock;
import com.hxtec.polaris.mapper.ShopStockMapper;
import com.hxtec.polaris.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Caps
 * @date 2019/11/23
 */
@Service
public class StockServiceImpl implements StockService {
    @Autowired
    private ShopStockMapper shopStockMapper;

    /**
     * 根据sku获取库存
     * @param sku
     * @return
     */
    @Override
    public ShopStock getStockInfoBuSku(int sku) {
        ShopStock shopStock=new ShopStock();
        shopStock.setSku(sku);
        return shopStockMapper.selectOne(shopStock);
    }

    /**
     * 加购更新库存
     * @param sku
     */
    @Override
    public void updateStockInfoBySku(int sku) {
        ShopStock stockInfoBuSku = this.getStockInfoBuSku(sku);
        stockInfoBuSku.setAvailable(stockInfoBuSku.getAvailable()-1);
        stockInfoBuSku.setLock(stockInfoBuSku.getLock()+1);
        shopStockMapper.updateByPrimaryKeySelective(stockInfoBuSku);
    }
}
